﻿
using AutoMapper;
using Modules.Corp;
using Modules.Project;
using PmSoft;
using System.ComponentModel.DataAnnotations;

namespace ManagementApi.Models.System.ProjectCorpWageAuth
{
    /// <summary>
    /// 项目参建企业非正常工资单授权
    ///</summary>
    public class ProjectCorpWageAuthEditForm
    {
        /// <summary>
        /// 主键 
        ///</summary>
        [Display(Name = "主键")]
        public int? Id { get; set; }
        /// <summary>
        /// 项目id 
        ///</summary>
        [Display(Name = "项目id")]
        [Required(ErrorMessage = "{0}不能为空")]
        public int ProjectId { get; set; }
        /// <summary>
        /// 参建企业id 
        ///</summary>
        [Display(Name = "参建企业id")]
        [Required(ErrorMessage = "{0}不能为空")]
        public int CorpId { get; set; }
        /// <summary>
        /// 允许发放月份 
        ///</summary>
        [Display(Name = "允许发放月份")]
        [Required(ErrorMessage = "{0}不能为空")]
        public int Month { get; set; }
        /// <summary>
        /// 允许发放最大金额 
        ///</summary>
        [Display(Name = "允许发放最大金额")]
        [Required(ErrorMessage = "{0}不能为空")]
        public decimal MaxPayAmount { get; set; }
        /// <summary>
        /// 允许发放最多人数 
        ///</summary>
        [Display(Name = "允许发放最多人数")]
        [Required(ErrorMessage = "{0}不能为空")]
        public int MaxPersonCount { get; set; }

        #region 扩展字段
        public string ProjectName {  get; set; }
        public string CorpName {  get; set; }
        #endregion
    }
    public static class ProjectCorpWageAuthExtensions
    {
        public static ProjectCorpWageAuthEditForm AsForm(this Modules.ProjectCorpWageAuth entity)
        {
            ProjectCorpWageAuthEditForm form = new();
            var mapper = ServiceAccessor.GetService<IMapper>();
            mapper.Map(entity, form);
            var corpService = ServiceAccessor.GetService<CorpService>();
            form.CorpName = corpService.GetCorpInfo(entity.CorpId)?.Name ?? string.Empty;
            var projectService = ServiceAccessor.GetService<ProjectService>();
            form.ProjectName = projectService.GetProjectInfo(entity.ProjectId)?.Name ?? string.Empty;
            return form;
        }
    }
}
